<template>
    <div class="back">
        <el-container>
            <el-header height="10%">
                <div class="header-div">
                    <img class="img-title" src="@/assets/img/index/title.png"/>
                    <div class="header-font">桐庐县江南镇人民政府</div>
                </div>
                <div style="width:400px;margin-top:15px;margin-right:18px">
                    <el-input v-model="search" placeholder="搜索" style="width: 380px; position: relative; padding-right: 15px;" size="small" @keyup.enter.native="doSearch">  
                        <i slot="suffix" class="el-input__icon el-icon-search" @click="doSearch" style="position: absolute; right: 15px;"></i>  
                    </el-input>
                </div>
                <div class="user">
                    <span class="username">{{username}}</span>
                    <span><el-avatar :size="40" :src="avatar"></el-avatar></span>
                </div>
            </el-header>
            <el-container>
                <el-aside width="10%">
                    <div class="left-region">
                        <div class="goback" @click="back">
                            <img class="img-back" src="@/assets/img/back.png"/>
                            <span>返回</span>
                        </div>
                        <div :class="['nav','active']">决策会议申请</div>
                    </div>
                </el-aside>
                <el-main>
                    <div class="right-region">
                        <div class="post-head">
                            <div>
                                <span :class="['head-item',{'active2':show[0]}]" @click="showDiv(0)">流程表单</span>
                                <span :class="['head-item',{'active2':show[1]}]" @click="showDiv(1)">流程图</span>
                                <span :class="['head-item',{'active2':show[2]}]" @click="showDiv(2)">流程状态</span>
                            </div>
                            <div class="post-button-all">
                                <el-button class="post-button" size="mini" @click="submitForm">提交</el-button>
                                <el-button class="post-button" size="mini">保存</el-button>
                            </div>
                        </div>
                        <div class="division"></div>
                        <div>
                            <div v-show="show[0]">
                                <div style="font-weight:600;">基础信息</div>
                                <el-form ref="formData" :model="formData" :rules="rules" size="medium" label-width="140px">
                                    <el-row :gutter="15">
                                            <el-col :span="10">
                                            <el-form-item label="提交事项" prop="submission">
                                                <el-input v-model="formData.submission" clearable :style="{width: '100%'}">
                                                </el-input>
                                            </el-form-item>
                                            </el-col>
                                            <el-col :span="10">
                                            <el-form-item label="提交科室" prop="subDept">
                                                <el-select v-model="formData.subDept" clearable :style="{width: '100%'}">
                                                <el-option v-for="(item, index) in subDept" :key="index" :label="item.label"
                                                    :value="item.value" :disabled="item.disabled"></el-option>
                                                </el-select>
                                            </el-form-item>
                                            </el-col>
                                            <el-col :span="10">
                                            <el-form-item label="经办人" prop="agent">
                                                <el-input v-model="formData.agent" clearable :style="{width: '100%'}"></el-input>
                                            </el-form-item>
                                            </el-col>
                                            <el-col :span="10">
                                            <el-form-item label="填报日期" prop="date">
                                                <el-date-picker v-model="formData.date" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                                                :style="{width: '100%'}" placeholder="填报日期" clearable></el-date-picker>
                                            </el-form-item>
                                            </el-col>
                                            <el-col :span="10">
                                            <el-form-item label="汇报人" prop="reporter">
                                                <el-input v-model="formData.reporter" clearable :style="{width: '100%'}">
                                                </el-input>
                                            </el-form-item>
                                            </el-col>
                                            <el-col :span="24">
                                            <el-form-item label="提交事项的基本情况及存在的问题、原因、具体的意见建议" prop="suggest">
                                                <el-input v-model="formData.suggest" type="textarea"
                                                :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
                                            </el-form-item>
                                            </el-col>
                                            <el-col :span="24">
                                            <el-form-item label="相关附件" prop="annex">
                                                <el-upload ref="annex" :file-list="annexfileList" :action="annexAction"
                                                :before-upload="annexBeforeUpload">
                                                <el-button size="small" type="primary">附件上传</el-button><span style="margin-left:15px;">(每个文件最大不超过50MB)</span>
                                                </el-upload>
                                            </el-form-item>
                                            </el-col>
                                    </el-row>
                                    <div class="division"></div>
                                    <div style="font-weight:600;">决策信息</div>
                                    <el-form-item label="分管领导(片长)意见" prop="leaderSuggest">
                                        <el-input v-model="formData.leaderSuggest" type="textarea"
                                        :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
                                    </el-form-item>
                                    <el-form-item label="班子会意见" prop="classSuggest">
                                        <el-input v-model="formData.classSuggest" type="textarea"
                                        :autosize="{minRows: 4, maxRows: 4}" :style="{width: '100%'}"></el-input>
                                    </el-form-item>
                                </el-form>
                            </div>
                            <div v-show="show[1]">流程图</div>
                            <div v-show="show[2]">流程状态</div>
                        </div>
                        <div class="division"></div>
                    </div>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
export default {
    data () {
        return {
            show: [true,false,false],
            username: '用户名',
            avatar: '',
            search: '',  //搜索内容
            formData: {
                submission: undefined,
                subDept: undefined,
                agent: undefined,
                date: null,
                reporter: undefined,
                suggest: undefined,
                annex: null,
            },
            rules: {
                submission: [{
                required: true,
                message: '请输入提交事项',
                trigger: 'blur'
                }],
                subDept: [],
                agent: [{
                required: true,
                message: '请输入经办人',
                trigger: 'blur'
                }],
                date: [{
                required: true,
                message: '请选择填报日期',
                trigger: 'change'
                }],
                reporter: [{
                required: true,
                message: '请输入汇报人',
                trigger: 'blur'
                }],
                suggest: [{
                required: true,
                message: '请输入提交事项的基本情况及存在的问题、原因、具体的意见建议',
                trigger: 'blur'
                }],
            },
            annexAction: 'https://jsonplaceholder.typicode.com/posts/',
            annexfileList: [],
            subDept: [{
                "label": "选项一",
                "value": 1
            }, {
                "label": "选项二",
                "value": 2
            }],
        }
    },
    methods: {
        
        //搜索框点击搜索
        doSearch() {
            console.log(this.search);
        },
        back() {
            this.$router.push("/");
        },
        showDiv(index) {
            for (let i = 0; i < this.show.length; i++) {
                if (i == index) {
                    this.show.splice(i, 1, true)
                }else{
                    this.show.splice(i, 1, false)
                }
            }
        },
        submitForm() {
            this.$refs['formData'].validate(valid => {
                if (!valid) {
                    this.$message({
                        message: '请填写完整！',
                        type: 'warning'
                    });
                }
                // TODO 提交表单
                console.log(this.formData);
                console.log(this.meetAnnexfileList);
            })
        },
        //附件上传
        annexBeforeUpload(file) {
            let isRightSize = file.size / 1024 / 1024 < 50
            if (!isRightSize) {
                this.$message.error('文件大小超过 50MB')
            }
            return isRightSize
        },
        //新建会议上传附件成功后回调
        successUpload(response, file, meetAnnexfileList)	{
            console.log(response);
            this.formData.meetAnnex = response.data.url;
        },
        //新建通知上传附件成功后回调
        successUpload2(response, file, meetAnnexfileList)	{
            console.log(response);
            this.noticeFormData.noticeAnnex = response.data.url;
        },
    }
}
</script>

<style scoped>
    .el-header{
        display: flex;
        margin-top: 20px;
        justify-content: space-between;
    }
    .el-aside{
        height: 10%;
        margin-left: 40px;
        padding: 5px 10px 5px 10px;
        background-color: rgb(60, 136, 172);
        border-radius: 8px;
        color: white;
    }
    .el-main{
        height: 95%;
        margin-right: 100px;
        margin-left: 20px;
        border-radius: 10px;
        background-color: white;
        overflow:hidden;
    }
    .back{
        background: url("../../assets/img/background.png");
        background-size: 100% 100%;
        display: flex;
        height: 100%;
        vertical-align:top;
    }
    .right-region{
        width: 100%;
        height: 100%;
        overflow:hidden;
    }
    .img-title{
        width: 190px;
        height: 190px;
        margin-top: -45px;
        margin-left: -50px;
    }
    .header-div{
        margin-top: -20px;
        vertical-align:middle;
        display: flex;
    }
    .header-font{
        font-size: 35px;
        margin-top: 30px;
        margin-left: -50px;
        color: white;
    }
    .user *{
        font-size: 15px;
        vertical-align:middle;
        margin-top: 10px;
    }
    .user{
        margin-right: 80px;
    }
    .nav{
        width: 90%;
        margin: 0 auto;
        text-align: center;
        cursor:pointer;
        margin-bottom: 10px;
        height: 30px;
        line-height: 30px;
        border-radius: 8px;
    }
    .active{
        background-color: rgb(245, 170, 32);
    }
    .img-back{
        width: 20px;
        height: 20px;
    }
    .goback *{
        font-size: 15px;
        vertical-align:middle;
    }
    .goback{
        width: 90%;
        margin: 0 auto;
        text-align: center;
        margin-bottom: 10px;
        cursor: pointer;
    }
    
    .post-head{
        width: 100%;
        display: flex;
        justify-content: space-between;
        font-weight: 500;
    }
    /* 按钮区域样式 */
    .post-button-all{
        margin-right: 60px;
    }
    /* 单个按钮样式 */
    .post-button{
        background-color: rgb(60, 136, 172);
        color: white;
        border-radius: 5px;
    }
    .head-item{
        margin-left: 25px;
        cursor:pointer;
        padding-left: 10px;
        padding-right: 10px;
    }
    .active2{
        border-bottom: 2px solid rgb(52, 186, 240);
    }
    /* 分割线 */
    .division{
        width: 100%;
        margin: 0 auto;
        height: 2px;
        background-color: rgb(209, 208, 208);
        margin-top: 5px;
        margin-bottom: 15px;
    }
</style>